package mixed;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.UIManager;

public class HomeWork614 extends Frame implements ActionListener {

	private TextField input;
	private TextArea output;
	private Button addTxtBtn;
	private Button addLineBtn;

	public HomeWork614() {
		Panel p = new Panel();
		add(p, BorderLayout.NORTH);

		input = new TextField(30);
		p.add(input);

		addTxtBtn = new Button("Add");
		addTxtBtn.addActionListener(this);
		p.add(addTxtBtn);

		addLineBtn = new Button("Add Line");
		addLineBtn.addActionListener(this);
		p.add(addLineBtn);

		output = new TextArea(50, 30);
		add(output, BorderLayout.CENTER);

		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});

		setPreferredSize(new Dimension(400, 500));
		pack();
		setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		Object eventSource = e.getSource();
		if (eventSource == addTxtBtn) {
			output.append(input.getText());
		} else if (eventSource == addLineBtn) {
			output.append(input.getText());
			output.append(System.getProperty("line.separator"));
		}
	}

	public static void main(String[] args) {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}

		new HomeWork614();
	}
}
